package com.sso.controller;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.sso.entity.Task;
import com.sso.filter.R;
import com.sso.service.TaskService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author xia
 * @since 2022-07-23
 */
@RestController
@CrossOrigin
@Api(tags = "任务管理接口")
@RequestMapping("/shale_porosity/task")
public class TaskController {
    @Autowired
    private TaskService taskService;
    @GetMapping("/{current}/{limit}/{statusId}")
    @ApiOperation("分类查询")
    public R look(@PathVariable int statusId, @PathVariable Long current, @PathVariable Long limit){
        QueryWrapper<Task> queryWrapper = new QueryWrapper<>();
        queryWrapper.lambda().eq(Task::getTaskStatus,statusId);
        Page<Task> page = new Page<>(current, limit);
        queryWrapper.orderByDesc("id");
        taskService.page(page, queryWrapper);
        long total = page.getTotal();
        return R.ok().put("total", total).put("raw", page.getRecords());
    }

    @GetMapping("/{current}/{limit}")
    @ApiOperation("分页展示所有任务")
    public R getAllTasks(@PathVariable Long current, @PathVariable Long limit) {
        Page<Task> page = new Page<>(current, limit);
        QueryWrapper<Task> queryWrapper = new QueryWrapper<>();
        queryWrapper.orderByDesc("id");
        taskService.page(page, queryWrapper);
        long total = page.getTotal();
        return R.ok().put("total", total).put("raw", page.getRecords());
    }
}
